We know that to judge the string length in php, we only need to use the strlen () and mb_strlen () functions, but it is not as simple as we think, especially when it comes to a mix of Chinese and English, the above functions are a little inadequate.
Not updated for several daysArticleAlas, people are just lazy.
First, download a copy of dvbbs. php beta1CodeDecompress the package and put aside the PHP code to find out your MySQL manual. If there is no manual, check the following instance
The following describes the source code and simple test of the two versions of functions. At last, I will provide a more practical string truncation function. Note: The string truncation issues discussed here are all Chinese strings for UTF-8
Compare the php version of the discuz and ecshop truncation string functions. The following describes the source code and simple test of the two versions of functions. at last, I will provide a more practical string truncation function. Note: The
Strlen ()
PHP strlen () function
Definitions and usage
The strlen () function returns the length of the string.
Grammar
Strlen (String)
Parameters: StringDescription: Required. Specify the string to check.
The code is as follows
How to limit the number of words in PHP to the output of the article, the rest of the "..." means?
Dear brother, The little girl just learned PHP, when the content of the article output,
Because of the content of the article too much, make the
However, as long as the character string appears Chinese characters, it may cause PHP substr Chinese garbled characters, because of the Chinese UTF-8 encoding, each Chinese character occupies 3 bytes, while GB2312 occupies 2 bytes, English occupies 1
In the previous article we gave you the implementation of the PHP intercept string, and PHP interception of the use of Chinese strings, then we in the interception of Chinese strings, a lot of time will appear garbled problem, then we will introduce
Here are two versions of the function of the source code and a simple test, and finally I will give a more practical string intercept function. It should be noted that the string interception problem discussed here is the Chinese character string
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.